////////////////////////////////////////////////
//	File			:	"CPlayer.cpp"
//
//	Author			:	Steven Seufert (SMS)
//			
//	Last Modified	:	January 18, 2012
//
//	Purpose			:	To implement all functionality for the player class
/////////////////////////////////////////////////
#include "CPlayer.h"
#include "Globals.h"

#include "SGD Wrappers\CSGD_TextureManager.h"
#include "CBitmapFont.h"
#include "CGame.h"
#include "CHud.h"

CPlayer::CPlayer()
{
	SetRotation(0.0f);
	/*SetPosX(0);
	SetPosY(0);*/
	SetVelX(0);
	SetVelY(0);
	SetWidth(29);
	SetHeight(32);
	SetScale(1.0f);
//	SetRotation(0);
	SetImageID(PLAYER_SELF, CSGD_TextureManager::GetInstance()->LoadTexture("resources/graphics/Link Shield.png"));
	SetImageID(PLAYER_HEALTH_BAR, CSGD_TextureManager::GetInstance()->LoadTexture("resources/graphics/StS_bar 3 B.png"));
	SetImageID(PLAYER_MANA_BAR, CSGD_TextureManager::GetInstance()->LoadTexture("resources/graphics/blue bar.png"));
	SetImageID(PLAYER_BAR_BORDER, CSGD_TextureManager::GetInstance()->LoadTexture("resources/graphics/bar border.png"));
	
	SetHealth(100);
	SetMaxHealth(100);
	SetMana(100);
	SetMaxMana(100);
	SetNumLives(CGame::GetInstance()->GetStartingLives());
	SetNumSkeletons(0);
	m_nMaxSkeletons = 2;

	SetOwnerType (OWNER_PLAYER);
	m_unOMGroupID = OMG_PLAYERS;
	SetDamageReduction(0);

	SetIsAlive(true);
	SetHasArmor(false);
	SetIsEmpowered(false);
	SetHasARemoteMine(false);
	SetHasADecoy(false);
	SetHasABarrier(false);
	SetIsImmolating(false);
	SetIsSprinting(false);
	SetHasASymbolOfFear(false);

	SetArmorCurrentTime(-1.0f);
	SetArmorMaxTime(-1.0f);
	SetImmolationTime(-1.0f);
	SetImmolationRate(-1.0f);
	SetAccruedSprintTime(-1.0f);
	SetSprintMaxTime(-1.0f);

	for (int index = 0; index < 4; index++)
	{
		spellSlot[index] = NULL;
	}
	
}

CPlayer::~CPlayer()
{

}

// update the player every frame
void CPlayer::Update(float fElapsedTime)
{
	
}

// show up on screen
void CPlayer::Render(void)
{
	CSGD_TextureManager::GetInstance()->Draw(GetImageID(PLAYER_SELF), GetPosX(), GetPosY(), GetScale(), GetScale(), 0, (float)(GetWidth() >> 1), (float)(GetHeight() >> 1), GetRotation());

	RenderHUD();
}

// draws buffs and debuffs to the individual player's portion of the HUD
void CPlayer::RenderHUD()
{
	CSGD_TextureManager::GetInstance()->Draw(GetImageID(PLAYER_BAR_BORDER), GetPosX(), GetPosY() + GetHeight() + 39, 0.4f, GetScale() * 0.5f);
	CSGD_TextureManager::GetInstance()->Draw(GetImageID(PLAYER_HEALTH_BAR), GetPosX(), GetPosY() + GetHeight() + 40, ((float)m_nHealth / (float)m_nMaxHealth) * 0.4f, GetScale() * 0.5f);

	CSGD_TextureManager::GetInstance()->Draw(GetImageID(PLAYER_BAR_BORDER), GetPosX(), GetPosY() + GetHeight() + 49, 0.4f, GetScale() * 0.5f);
	CSGD_TextureManager::GetInstance()->Draw(GetImageID(PLAYER_MANA_BAR), GetPosX(), GetPosY() + GetHeight() + 50, ((float)m_nMana / (float)m_nMaxMana) * 0.4f, GetScale() * 0.5f);
	
	CBitmapFont::GetInstance()->SetScale(0.2f);
	// render own buffs/debuffs
	switch(m_nPlayerNumber)
	{
	case 1:	// player 1
		{
			if (m_bIsSprinting)
			{
				/*RECT rSpeed = {450, 501, 514, 533};*/
				/*RECT rSpeed = {500, 502, 564, 534};*/
				RECT rSpeed = {108, 502, 172, 534};
				CBitmapFont::GetInstance()->PrintInRect("1/2 Speed", &rSpeed, ALIGN_LEFT, D3DCOLOR_XRGB(0, 225, 0));
			}
			else if (m_bIsSlowed)
			{
				/*RECT rSpeed = {450, 501, 525, 533};*/
				/*RECT rSpeed = {500, 502, 564, 534};*/
				RECT rSpeed = {108, 502, 172, 534};
				CBitmapFont::GetInstance()->PrintInRect("Slow", &rSpeed, ALIGN_LEFT, D3DCOLOR_XRGB(255, 0, 75));
			}

			if (m_bIsEmpowered)
			{
				/*RECT rEmpowered = {525, 501, 689, 533};*/
				/*RECT rEmpowered = {564, 502, 628, 534};*/
				RECT rEmpowered = {172, 502, 236, 534};
				CBitmapFont::GetInstance()->PrintInRect("2X Damage", &rEmpowered, ALIGN_CENTER, D3DCOLOR_XRGB(0, 225, 0));
			}

			if (m_bHasArmor)
			{
				/*RECT rArmor = {600, 501, 675, 533};*/
				/*RECT rArmor = {628, 502, 692, 534};*/
				RECT rArmor = {236, 502, 300, 534};
				CBitmapFont::GetInstance()->PrintInRect("Armor", &rArmor, ALIGN_RIGHT, D3DCOLOR_XRGB(0, 225, 0));
			}

			RECT rLives = {0, 502, 108, 534};
			CBitmapFont::GetInstance()->PrintInRect("Lives 10", &rLives, ALIGN_CENTER, D3DCOLOR_XRGB(225, 225, 225));
		}
		break;

	case 2:	// player 2
		{ 
			if (m_bIsSprinting)
			{
				RECT rSpeed = {475, 502, 564, 534};
				CBitmapFont::GetInstance()->PrintInRect("2X Speed", &rSpeed, ALIGN_LEFT, D3DCOLOR_XRGB(0, 225, 0));
			}
			else if (m_bIsSlowed)
			{
				RECT rSpeed = {475, 502, 564, 534};
				CBitmapFont::GetInstance()->PrintInRect("Slow", &rSpeed, ALIGN_LEFT, D3DCOLOR_XRGB(255, 0, 75));
			}

			if (m_bIsEmpowered)
			{
				RECT rEmpowered = {564, 502, 628, 534};
				CBitmapFont::GetInstance()->PrintInRect("2X Damage", &rEmpowered, ALIGN_CENTER, D3DCOLOR_XRGB(0, 225, 0));
			}

			if (m_bHasArmor)
			{
				RECT rArmor = {628, 502, 692, 534};
				CBitmapFont::GetInstance()->PrintInRect("Armor", &rArmor, ALIGN_RIGHT, D3DCOLOR_XRGB(0, 225, 0));
			}

			RECT rLives = {692, 502, 800, 534};
			CBitmapFont::GetInstance()->PrintInRect("Lives 10", &rLives, ALIGN_CENTER, D3DCOLOR_XRGB(225, 225, 225));
		}
		break;
	}

	switch(m_nPlayerNumber)
	{
	case 1:
		{
			CHud::GetInstance()->SetXPosition("A button.png",  83);
			CHud::GetInstance()->SetXPosition("B button.png", 147);
			CHud::GetInstance()->SetXPosition("X button.png", 211);
			CHud::GetInstance()->SetXPosition("Y button.png", 275);

			CHud::GetInstance()->SetYPosition("A button.png", 536);
			CHud::GetInstance()->SetYPosition("B button.png", 536);
			CHud::GetInstance()->SetYPosition("X button.png", 536);
			CHud::GetInstance()->SetYPosition("Y button.png", 536);

			CHud::GetInstance()->Draw("A button.png");
			CHud::GetInstance()->Draw("B button.png");
			CHud::GetInstance()->Draw("X button.png");
			//CHud::GetInstance()->Draw("Y button.png");
		}
		break;

	case 2: 
		{
			CHud::GetInstance()->SetXPosition("Y button.png", 686);
			CHud::GetInstance()->SetXPosition("X button.png", 622);
			CHud::GetInstance()->SetXPosition("B button.png", 558);
			CHud::GetInstance()->SetXPosition("A button.png", 494);
			
			CHud::GetInstance()->SetYPosition("A button.png", 536);
			CHud::GetInstance()->SetYPosition("B button.png", 536);
			CHud::GetInstance()->SetYPosition("X button.png", 536);
			CHud::GetInstance()->SetYPosition("Y button.png", 536);

			CHud::GetInstance()->Draw("A button.png");
			CHud::GetInstance()->Draw("B button.png");
			CHud::GetInstance()->Draw("X button.png");
			//CHud::GetInstance()->Draw("Y button.png");
		}
		break;
	}
}

// set default attributes
void CPlayer::Reset()
{
	//SetPosX(to be determined);
	//SetPosY(to be determined);
	SetRotation(0);
	
	SetHealth(m_nMaxHealth);	
	SetMana(m_nMaxMana);

	SetDamageReduction(0);

	SetIsAlive(true);
	SetHasArmor(false);
	SetIsEmpowered(false);
	SetIsImmolating(false);
	SetIsSprinting(false);

	SetArmorCurrentTime(-1.0f);
	SetArmorMaxTime(-1.0f);
	SetImmolationTime(-1.0f);
	SetImmolationRate(-1.0f);
	SetAccruedSprintTime(-1.0f);
	SetSprintMaxTime(-1.0f);
}

// check collision against all other objects 
bool CPlayer::CheckCollision(IBaseInterface* pBase )
{
	// TODO: fix this
	return false;
}

void CPlayer::HandleEvent(CEvent* pEvent)
{

}